#include "lvgl/lvgl.h"
#include "login.h"
#include "widget.h"
#include <stdio.h>

// 当前显示的图片索引,每张图片对应一个索引，1.bmp--5.bmp 对应 lsg_path[0]--lsg_path[4]
static int current_pic_index = 0;
// 图片的路径(在当前目录下)
static const char *lsg_path[5] = {
    "A:/lsg/1.bmp",
    "A:/lsg/2.bmp",
    "A:/lsg/3.bmp",
    "A:/lsg/4.bmp",
    "A:/lsg/6.bmp",
};

static const char *lsg2_path[2] = {
    "A:/lsg/5.bmp",
    
    "A:/lsg/7.bmp",
};

static int current_pic_index2 = 0;
// 图片显示对象指针，用于显示图片
static lv_obj_t *photo_pic = NULL;
static lv_obj_t *photo_pic2 = NULL;

void textarea_event_cb(lv_event_t * e)
{
    //获取触发事件的对象的地址，也就是文本框的地址
    lv_obj_t * ta = lv_event_get_target(e);
    //获取用户数据，也就是软键盘的地址
    lv_obj_t * kb = (lv_obj_t*)lv_event_get_user_data(e);
    //获取事件类型
    lv_event_code_t code = lv_event_get_code(e);
    if(code == LV_EVENT_FOCUSED)//聚焦事件
    {
        //显示软键盘
        lv_obj_remove_flag(kb,LV_OBJ_FLAG_HIDDEN);
        //关联被聚焦的文本框和软键盘
        lv_keyboard_set_textarea(kb,ta);
    }
    else if(code == LV_EVENT_DEFOCUSED)//失去聚焦事件
    {
        //隐藏软键盘
        lv_obj_add_flag(kb,LV_OBJ_FLAG_HIDDEN);
    }

}
//左按钮（left）点击事件的回调函数
void button_left_click_event_cb(lv_event_t * e)
{
    if(photo_pic != NULL) {
    // 计算上一张图片的索引，循环显示
    current_pic_index = (current_pic_index - 1 + 5) % 5;
    // 更新显示的图片
    lv_image_set_src(photo_pic, lsg_path[current_pic_index]);
    }
    if(photo_pic2 != NULL)//使用else if在进入用户1之后photo_pic不为NULL，进入用户2时photo_pic、photo_pic2都不为NULL，所以无法执行else if中的语句
    {
        // 计算上一张图片的索引，循环显示
        current_pic_index2 = (current_pic_index2 - 1 + 3) % 3;
        // 更新显示的图片
        lv_image_set_src(photo_pic2, lsg_path[current_pic_index2]);
    }
}
//右按钮（right）点击事件的回调函数
void button_right_click_event_cb(lv_event_t * e)
{
    if(photo_pic != NULL) {
    // 计算下一张图片的索引，循环显示
    current_pic_index = (current_pic_index + 1) % 5;
    // 更新显示的图片
    lv_image_set_src(photo_pic,lsg_path[current_pic_index]);
    }
    if(photo_pic2 != NULL)
    {
        // 计算下一张图片的索引，循环显示
        current_pic_index2 = (current_pic_index2 + 1) % 3;
        // 更新显示的图片
        lv_image_set_src(photo_pic2, lsg_path[current_pic_index2]);
    }
}
//放大按钮(zoom_in_but)点击事件的回调函数
void zoom_in_but_click_event_cb(lv_event_t * e)
{
    //获取当前图片对象
    lv_obj_t *obj = photo_pic?photo_pic:photo_pic2;
    //获取当前图片的缩放比例
    uint16_t zoom = lv_img_get_zoom(obj);
    //设置图片的缩放比例
    if(zoom < 1024){
        zoom += 10;
        lv_img_set_zoom(obj, zoom);
    }

}
//缩小按钮(zoom_out_but)点击事件的回调函数
void zoom_out_but_click_event_cb(lv_event_t * e)
{
    //获取当前图片对象
    lv_obj_t *obj = photo_pic?photo_pic:photo_pic2;
    //获取当前图片的缩放比例
    uint16_t zoom = lv_img_get_zoom(obj);
    //设置图片的缩放比例
    if(zoom > 100){
        zoom -= 10;
        lv_img_set_zoom(obj, zoom);
    }

}

//顺时针按钮(shun_but)点击事件的回调函数
void shun_but_click_event_cb()
{
    //获取当前图片对象
    lv_obj_t *obj = photo_pic?photo_pic:photo_pic2;
    
    //获取图片宽高
    lv_coord_t width = lv_obj_get_width(obj);
    lv_coord_t height = lv_obj_get_height(obj);

    //图片为中心旋转
    lv_img_set_pivot(obj,400,240);

    //获取当前角度
    uint16_t angle = lv_img_get_angle(obj);
    //累加90°
    angle += 90;
    // 确保角度在 0 - 359 度范围内
    angle %= 360;
    lv_img_set_angle(obj, angle);
    
    lv_obj_update_layout(obj); //更新图片布局
    lv_obj_center(obj);//居中图片
}
//逆时针按钮(ni_but)点击事件的回调函数
void ni_but_click_event_cb()
{
    //获取当前图片对象
    lv_obj_t *obj = photo_pic?photo_pic:photo_pic2;
    
    //获取图片宽高
    lv_coord_t width = lv_obj_get_width(obj);
    lv_coord_t height = lv_obj_get_height(obj);

    //图片为中心旋转
    lv_img_set_pivot(obj, 400,240);

    //获取当前角度
    uint16_t angle = lv_img_get_angle(obj);
    //逆时针旋转90°，需要注意角度是uint16_t类型，不能直接减
    angle = (angle >= 90) ? (angle - 90) : (angle + 270);
    // 确保角度在 0 - 359 度范围内
    angle %= 360;
    lv_img_set_angle(obj, angle);
    
    lv_obj_update_layout(obj); //更新图片布局
    lv_obj_center(obj);        //居中图片
}
//提示框界面（OK）点击事件的回调函数
void button_OK_click_event_cb(lv_event_t * e)
{
    //隐藏new_win1
    lv_obj_t * ok_but = lv_event_get_target(e);
    lv_obj_t * new_win1 = lv_obj_get_parent(ok_but);
    lv_obj_add_flag(new_win1,LV_OBJ_FLAG_HIDDEN);
    //显示登录界面
    lv_obj_clear_flag(lv_scr_act(),LV_OBJ_FLAG_HIDDEN);

}
//返回登录界面按钮回调函数
void button_back_click_event_cb(lv_event_t * e)
{
    // 获取触发事件的按钮
    lv_obj_t * back_but = lv_event_get_target(e);
    // 获取当前窗口（new_win1）
    lv_obj_t * current_window = lv_obj_get_parent(back_but);
    // 从用户数据中获取登录窗口指针
    lv_obj_t * login_window = (lv_obj_t*)lv_event_get_user_data(e);
    // 隐藏当前窗口
    lv_obj_add_flag(current_window, LV_OBJ_FLAG_HIDDEN);
    // 显示登录窗口
    lv_obj_clear_flag(login_window, LV_OBJ_FLAG_HIDDEN);
}
//登录按钮（login）点击事件的回调函数
void button_click_event_cb(lv_event_t * e)
{
    //点击了登录按钮，需要获取用户输入的用户名和密码
    //获取用户数据
    lv_obj_t * win = (lv_obj_t*)lv_event_get_user_data(e);
    if (win == NULL) return; // 检查 win 是否为 NULL
    //用户数据是登录窗口的指针，我们需要用到它的子对象：两个文本输入框的地址
    lv_obj_t * use_ta = lv_obj_get_child(win,3);
    lv_obj_t * pass_ta = lv_obj_get_child(win,4);

    // 检查文本输入框是否为 NULL
    if (use_ta == NULL || pass_ta == NULL) return;

    //获取用户输入的用户名和密码
    const char * user = lv_textarea_get_text(use_ta);
    const char * pass = lv_textarea_get_text(pass_ta);
    if(strcmp(user,"lsg")==0 && strcmp(pass,"123456")==0)//用户1
    {
        printf("登录成功\n");
        //隐藏登录界面，显示新的界面
        lv_obj_add_flag(win,LV_OBJ_FLAG_HIDDEN);
        //创建一个存放图片的窗口
        lv_obj_t*new_win1 = lv_obj_create(lv_scr_act());
        lv_obj_set_pos(new_win1,0,0);
        lv_obj_set_size(new_win1,800,480);

        static lv_style_t obj_style;
        //初始化样式
        lv_style_init(&obj_style);
        //设置背景颜色
        lv_color_t bg_color={255,255,255};//白色
        lv_style_set_bg_color(&obj_style,bg_color);
        //设置背景透明度， 0完全透明(意思是看不见)，255不透明
        lv_style_set_bg_opa(&obj_style,255);
        //设置边框宽度
        lv_style_set_border_width(&obj_style,5);
        //设置边框颜色
        lv_color_t border_color = {253,251,115};//天蓝色 
        lv_style_set_border_color(&obj_style,border_color);
        //设置边框透明度
        lv_style_set_border_opa(&obj_style,255);
        //设置四个角的弧度,第二个参数对应半径,0表示90度（没有弧度），值越大，弧度越大
        lv_style_set_radius(&obj_style,5);
        //给对象增加样式，默认状态下生效
        lv_obj_add_style(new_win1,&obj_style,LV_STATE_DEFAULT);

        //图片显示
        //创建图片所在的对象
        photo_pic = lv_img_create(new_win1);
        //图片显示对象
        lv_image_set_src(photo_pic, lsg_path[current_pic_index]);
        //图片显示位置
        lv_obj_set_pos(photo_pic,135,0);    

    //返回按钮
        lv_obj_t * back_but = lv_button_create(new_win1);
        lv_obj_set_size(back_but,90,60);
        lv_obj_set_pos(back_but,5,5);
        //文字
        lv_obj_t * back_but_label = lv_label_create(back_but);
        lv_label_set_text(back_but_label,"Esc");
        //初始化样式
        lv_style_init(&back_button_style);
        //设置背景颜色
        lv_color_t back_bg_color={246,130,50};//蓝色
        lv_style_set_bg_color(&back_button_style,back_bg_color);
        //设置背景透明度， 0完全透明(意思是看不见)，255不透明
        lv_style_set_bg_opa(&back_button_style,100);// 透明
        //设置边框宽度
        lv_style_set_border_width(&back_button_style,3);
        //设置边框颜色
        lv_color_t back_border_color = {85,253,255};//黄色 
        lv_style_set_border_color(&back_button_style,back_border_color);
        //设置边框透明度
        lv_style_set_border_opa(&back_button_style,200);
        //设置四个角的弧度,第二个参数对应半径,0表示90度（没有弧度），值越大，弧度越大
        lv_style_set_radius(&back_button_style,5);
        //设置文本字体大小
        lv_style_set_text_font(&back_button_style,&lv_font_montserrat_30);
        //设置字体颜色
        lv_style_set_text_color(&back_button_style,lv_color_hex(0xffffff));
        //给返回按钮添加样式
        lv_obj_add_style(back_but,&back_button_style,LV_STATE_DEFAULT);
        lv_obj_add_event_cb(back_but,button_back_click_event_cb,LV_EVENT_CLICKED,win);
    //左右按钮图片
        lv_obj_t * left_image = lv_image_create(new_win1);
        lv_image_set_src(left_image,"A:/lsg/left.bmp");
        lv_obj_set_pos(left_image,15,170);
        lv_obj_t * right_image = lv_image_create(new_win1);
        lv_image_set_src(right_image,"A:/lsg/right.bmp");
        lv_obj_set_pos(right_image,610,170);
        //左右按钮
        //创建登左右按钮，以新窗口为父对象
        lv_obj_t * left_but = lv_button_create(new_win1);
        lv_obj_t * right_but = lv_button_create(new_win1);
        //设置大小和位置
        lv_obj_set_size(left_but,75,140);
        lv_obj_set_pos(left_but,15,170);
        lv_obj_set_size(right_but,75,140);
        lv_obj_set_pos(right_but,610,170);

        //初始化按钮样式
        init_lef_rig_button_style();

        lv_obj_add_style(left_but,&lef_rig_button_style,LV_STATE_DEFAULT);
        lv_obj_add_style(right_but,&lef_rig_button_style,LV_STATE_DEFAULT);

        //添加左右按钮点击事件
        lv_obj_add_event_cb(left_but, button_left_click_event_cb, LV_EVENT_CLICKED, NULL);
        lv_obj_add_event_cb(right_but, button_right_click_event_cb, LV_EVENT_CLICKED, NULL);
    //放大缩小图片
        lv_obj_t * zoom_in_image = lv_image_create(new_win1);
        lv_image_set_src(zoom_in_image,"A:/lsg/big.bmp");
        lv_obj_set_pos(zoom_in_image,700,10);
        lv_obj_t * zoom_out_image = lv_image_create(new_win1);
        lv_image_set_src(zoom_out_image,"A:/lsg/small.bmp");
        lv_obj_set_pos(zoom_out_image,700,100);
        //创建放大，缩小按钮
        lv_obj_t * zoom_in_but = lv_button_create(new_win1);
        lv_obj_t * zoom_out_but = lv_button_create(new_win1);
        lv_obj_set_size(zoom_in_but,75,75);
        lv_obj_set_pos(zoom_in_but,700,10);
        lv_obj_set_size(zoom_out_but,75,75);
        lv_obj_set_pos(zoom_out_but,700,100);

        //初始化样式
        init_zoom_button_style();

        lv_obj_add_style(zoom_in_but,&zoom_button_style,LV_STATE_DEFAULT);
        lv_obj_add_style(zoom_out_but,&zoom_button_style,LV_STATE_DEFAULT);

        //添加点击事件
        lv_obj_add_event_cb(zoom_in_but, zoom_in_but_click_event_cb, LV_EVENT_CLICKED, NULL);
        lv_obj_add_event_cb(zoom_out_but, zoom_out_but_click_event_cb, LV_EVENT_CLICKED, NULL);
    //顺逆时针旋转图
        lv_obj_t * shun_image = lv_image_create(new_win1);
        lv_image_set_src(shun_image,"A:/lsg/shun.bmp");
        lv_obj_set_pos(shun_image,700,190);
        lv_obj_t * ni_image = lv_image_create(new_win1);
        lv_image_set_src(ni_image,"A:/lsg/ni.bmp");
        lv_obj_set_pos(ni_image,700,280);
        //创建旋转按钮
        lv_obj_t * shun_but = lv_button_create(new_win1);
        lv_obj_set_size(shun_but,75,75);
        lv_obj_set_pos(shun_but,700,190);
        lv_obj_t * ni_but = lv_button_create(new_win1);
        lv_obj_set_size(ni_but,75,75);
        lv_obj_set_pos(ni_but,700,280);

        //初始化样式
        init_zoom_button_style();

        lv_obj_add_style(shun_but,&zoom_button_style,LV_STATE_DEFAULT);
        lv_obj_add_style(ni_but,&zoom_button_style,LV_STATE_DEFAULT);

        //添加点击事件
        lv_obj_add_event_cb(shun_but, shun_but_click_event_cb, LV_EVENT_CLICKED, NULL);
        lv_obj_add_event_cb(ni_but, ni_but_click_event_cb, LV_EVENT_CLICKED, NULL);

    }
    else if(strcmp(user,"lsg2")==0 && strcmp(pass,"654321")==0)//用户2
    {
        printf("登录成功\n");
        //隐藏登录界面，显示新的界面
        lv_obj_add_flag(win,LV_OBJ_FLAG_HIDDEN);
        //创建一个存放图片的窗口
        lv_obj_t*new_win2 = lv_obj_create(lv_scr_act());
        lv_obj_set_pos(new_win2,0,0);
        lv_obj_set_size(new_win2,800,480);

        static lv_style_t obj_style;
        //初始化样式
        lv_style_init(&obj_style);
        //设置背景颜色
        lv_color_t bg_color={255,255,255};//白色
        lv_style_set_bg_color(&obj_style,bg_color);
        //设置背景透明度， 0完全透明(意思是看不见)，255不透明
        lv_style_set_bg_opa(&obj_style,255);
        //设置边框宽度
        lv_style_set_border_width(&obj_style,5);
        //设置边框颜色
        lv_color_t border_color = {221,174,232};//粉色 
        lv_style_set_border_color(&obj_style,border_color);
        //设置边框透明度
        lv_style_set_border_opa(&obj_style,255);
        //设置四个角的弧度,第二个参数对应半径,0表示90度（没有弧度），值越大，弧度越大
        lv_style_set_radius(&obj_style,5);
        //给对象增加样式，默认状态下生效
        lv_obj_add_style(new_win2,&obj_style,LV_STATE_DEFAULT);
        //图片显示
        //创建图片所在的对象
        photo_pic2 = lv_img_create(new_win2);
        //图片显示对象
        lv_image_set_src(photo_pic2, lsg_path[current_pic_index2]);
        //图片显示位置
        lv_obj_set_pos(photo_pic2,250,110);    

    //返回按钮
        lv_obj_t * back_but = lv_button_create(new_win2);
        lv_obj_set_size(back_but,90,60);
        lv_obj_set_pos(back_but,5,5);
        //文字
        lv_obj_t * back_but_label = lv_label_create(back_but);
        lv_label_set_text(back_but_label,"Esc");
        //初始化样式
        lv_style_init(&back_button_style);
        //设置背景颜色
        lv_color_t back_bg_color={85,253,255};//黄色
        lv_style_set_bg_color(&back_button_style,back_bg_color);
        //设置背景透明度， 0完全透明(意思是看不见)，255不透明
        lv_style_set_bg_opa(&back_button_style,100);// 透明
        //设置边框宽度
        lv_style_set_border_width(&back_button_style,3);
        //设置边框颜色
        lv_color_t back_border_color = {164,73,163};//紫色 
        lv_style_set_border_color(&back_button_style,back_border_color);
        //设置边框透明度
        lv_style_set_border_opa(&back_button_style,200);
        //设置四个角的弧度,第二个参数对应半径,0表示90度（没有弧度），值越大，弧度越大
        lv_style_set_radius(&back_button_style,5);
        //设置文本字体大小
        lv_style_set_text_font(&back_button_style,&lv_font_montserrat_30);
        //设置字体颜色
        lv_style_set_text_color(&back_button_style,lv_color_hex(0xFAABC5));
        //给返回按钮添加样式
        lv_obj_add_style(back_but,&back_button_style,LV_STATE_DEFAULT);
        lv_obj_add_event_cb(back_but,button_back_click_event_cb,LV_EVENT_CLICKED,win);
        
    //左右按钮图片
        lv_obj_t * left_image = lv_image_create(new_win2);
        lv_image_set_src(left_image,"/left.bmp");
        lv_obj_set_pos(left_image,15,170);
        lv_obj_t * right_image = lv_image_create(new_win2);
        lv_image_set_src(right_image,"/right.bmp");
        lv_obj_set_pos(right_image,610,170);
        //左右按钮
        //创建登左右按钮，以新窗口为父对象
        lv_obj_t * left_but = lv_button_create(new_win2);
        lv_obj_t * right_but = lv_button_create(new_win2);
        //设置大小和位置
        lv_obj_set_size(left_but,75,140);
        lv_obj_set_pos(left_but,15,170);
        lv_obj_set_size(right_but,75,140);
        lv_obj_set_pos(right_but,610,170);

        //初始化按钮样式
        init_lef_rig_button_style();

        lv_obj_add_style(left_but,&lef_rig_button_style,LV_STATE_DEFAULT);
        lv_obj_add_style(right_but,&lef_rig_button_style,LV_STATE_DEFAULT);

        //添加左右按钮点击事件
        lv_obj_add_event_cb(left_but, button_left_click_event_cb, LV_EVENT_CLICKED, NULL);
        lv_obj_add_event_cb(right_but, button_right_click_event_cb, LV_EVENT_CLICKED, NULL);
    //放大缩小图片
        lv_obj_t * zoom_in_image = lv_image_create(new_win2);
        lv_image_set_src(zoom_in_image,"/big.bmp");
        lv_obj_set_pos(zoom_in_image,700,10);
        lv_obj_t * zoom_out_image = lv_image_create(new_win2);
        lv_image_set_src(zoom_out_image,"/small.bmp");
        lv_obj_set_pos(zoom_out_image,700,100);
        //创建放大，缩小按钮
        lv_obj_t * zoom_in_but = lv_button_create(new_win2);
        lv_obj_t * zoom_out_but = lv_button_create(new_win2);
        lv_obj_set_size(zoom_in_but,75,75);
        lv_obj_set_pos(zoom_in_but,700,10);
        lv_obj_set_size(zoom_out_but,75,75);
        lv_obj_set_pos(zoom_out_but,700,100);

        //初始化样式
        init_zoom_button_style();

        lv_obj_add_style(zoom_in_but,&zoom_button_style,LV_STATE_DEFAULT);
        lv_obj_add_style(zoom_out_but,&zoom_button_style,LV_STATE_DEFAULT);

        //添加点击事件
        lv_obj_add_event_cb(zoom_in_but, zoom_in_but_click_event_cb, LV_EVENT_CLICKED, NULL);
        lv_obj_add_event_cb(zoom_out_but, zoom_out_but_click_event_cb, LV_EVENT_CLICKED, NULL);
    //顺逆时针旋转图
        lv_obj_t * shun_image = lv_image_create(new_win2);
        lv_image_set_src(shun_image,"/shun.bmp");
        lv_obj_set_pos(shun_image,700,190);
        lv_obj_t * ni_image = lv_image_create(new_win2);
        lv_image_set_src(ni_image,"/ni.bmp");
        lv_obj_set_pos(ni_image,700,280);
        //创建旋转按钮
        lv_obj_t * shun_but = lv_button_create(new_win2);
        lv_obj_set_size(shun_but,75,75);
        lv_obj_set_pos(shun_but,700,190);
        lv_obj_t * ni_but = lv_button_create(new_win2);
        lv_obj_set_size(ni_but,75,75);
        lv_obj_set_pos(ni_but,700,280);

        //初始化样式
        init_zoom_button_style();

        lv_obj_add_style(shun_but,&zoom_button_style,LV_STATE_DEFAULT);
        lv_obj_add_style(ni_but,&zoom_button_style,LV_STATE_DEFAULT);

        //添加点击事件
        lv_obj_add_event_cb(shun_but, shun_but_click_event_cb, LV_EVENT_CLICKED, NULL);
        lv_obj_add_event_cb(ni_but, ni_but_click_event_cb, LV_EVENT_CLICKED, NULL);
    }
    else
    {
        printf("登录失败\n");
        //弹出一个提示框
    //窗口
        lv_obj_t* prompt_box = lv_obj_create(lv_scr_act());
        if (prompt_box == NULL) return; // 检查提示框是否创建成功
        lv_obj_set_pos(prompt_box,250,100);
        lv_obj_set_size(prompt_box,300,240);
        static lv_style_t obj_style;
        //初始化样式
        lv_style_init(&obj_style);
        //设置背景颜色
        lv_color_t bg_color={192,192,192};//灰色
        lv_style_set_bg_color(&obj_style,bg_color);
        //设置背景透明度， 0完全透明(意思是看不见)，255不透明
        lv_style_set_bg_opa(&obj_style,200);
        //设置边框宽度
        lv_style_set_border_width(&obj_style,3);
        //设置边框颜色
        lv_color_t border_color = {0,0,0};//黑色 
        lv_style_set_border_color(&obj_style,border_color);
        //设置边框透明度
        lv_style_set_border_opa(&obj_style,255);
        //设置四个角的弧度,第二个参数对应半径,0表示90度（没有弧度），值越大，弧度越大
        lv_style_set_radius(&obj_style,5);
        //给对象增加样式，默认状态下生效
        lv_obj_add_style(prompt_box,&obj_style,LV_STATE_DEFAULT);

    //标签
        lv_obj_t * prompt_lab1 = lv_label_create(prompt_box);
        if (prompt_lab1 == NULL) return; // 检查标签是否创建成功
        lv_obj_set_size(prompt_lab1,200,40);
        lv_obj_set_pos(prompt_lab1,30,20);
        lv_label_set_text(prompt_lab1,"login failure ! ! !");
        lv_obj_t * prompt_lab2 = lv_label_create(prompt_box);
        if (prompt_lab2 == NULL) return; // 检查标签是否创建成功
        lv_obj_set_size(prompt_lab2,245,40);
        lv_obj_set_pos(prompt_lab2,10,65);
        lv_label_set_text(prompt_lab2,"please enter again !");
        //初始化样式
        init_prompt_label_style();
        lv_obj_add_style(prompt_lab1,&prompt_label_style,LV_STATE_DEFAULT);
        lv_obj_add_style(prompt_lab2,&prompt_label_style,LV_STATE_DEFAULT);
    //按钮
        lv_obj_t * OK_but = lv_button_create(prompt_box);
         if (OK_but == NULL) return; // 检查按钮是否创建成功
        lv_obj_set_size(OK_but,80,50);
        lv_obj_set_pos(OK_but,90,140);
        static lv_style_t OK_button_style;
        //初始化样式
        lv_style_init(&OK_button_style);
        //设置背景颜色
        lv_color_t OK_color={58,95,255};
        lv_style_set_bg_color(&OK_button_style,OK_color);
        //设置背景透明度， 0完全透明(意思是看不见)，255不透明
        lv_style_set_bg_opa(&OK_button_style,200);
        //设置边框宽度
        lv_style_set_border_width(&OK_button_style,3);
        //设置边框颜色
        lv_color_t OK_border_color = {255,255,255};//白色 
        lv_style_set_border_color(&OK_button_style,OK_border_color);
        //设置边框透明度
        lv_style_set_border_opa(&OK_button_style,255);
        //设置四个角的弧度,第二个参数对应半径,0表示90度（没有弧度），值越大，弧度越大
        lv_style_set_radius(&OK_button_style,5);
        //添加样式
        lv_obj_add_style(OK_but, &OK_button_style, LV_STATE_DEFAULT);

        lv_obj_t *lab = lv_label_create(OK_but);
        if (lab == NULL) return; // 检查标签是否创建成功
        lv_label_set_text(lab,"OK ! ");
        //设置文本字体大小
        lv_style_set_text_font(&OK_button_style,&lv_font_montserrat_22);
        //设置字体颜色
        lv_style_set_text_color(&OK_button_style,lv_color_hex(0xffffff));
        //给对象增加样式，默认状态下生效
        lv_obj_add_style(prompt_box,&OK_button_style,LV_STATE_DEFAULT);

        lv_obj_add_event_cb(OK_but,button_OK_click_event_cb,LV_EVENT_CLICKED,NULL);
    }
}

void login_winwod()
{
    //创建登录窗口
    lv_obj_t * win = lv_obj_create(lv_scr_act());
    if (win == NULL) return; // 检查提示框是否创建成功
    //设置窗口大小及位置
    lv_obj_set_size(win,800,480);
    lv_obj_set_pos(win,0,0);
    //设计样式  .....
    //设置背景图片
    lv_obj_t * image = lv_image_create(win);
    lv_image_set_src(image,"/bg.bmp");
    //lv_image_set_src(image,"A:/2.png");

    lv_obj_set_pos(image,10,6);

    //初始化标签样式表
    init_label_style();
    //创建用户名标签和密码标签，以登录窗口为父对象
    lv_obj_t * use_lab = lv_label_create(win);
    //设置标签的大小、位置、文本
    lv_obj_set_size(use_lab,130,50);
    lv_obj_set_pos(use_lab,150,175);
    lv_label_set_text(use_lab,"username");
    //增加样式表
    lv_obj_add_style(use_lab,&label_style,LV_STATE_DEFAULT);

    lv_obj_t * pass_lab = lv_label_create(win);
    //设置标签的大小、位置、文本
    lv_obj_set_size(pass_lab,130,50);
    lv_obj_set_pos(pass_lab,150,250);
    lv_label_set_text(pass_lab,"password");
    //增加样式表
    lv_obj_add_style(pass_lab,&label_style,LV_STATE_DEFAULT);
    
    //创建用户名和密码文本输入框,以登录窗口为父对象
    lv_obj_t * use_ta = lv_textarea_create(win);
    lv_obj_t * pass_ta = lv_textarea_create(win);
    //设置大小、位置
    lv_obj_set_size(use_ta,250,50);
    lv_obj_set_pos(use_ta,310,175);
    lv_obj_set_size(pass_ta,250,50);
    lv_obj_set_pos(pass_ta,310,250);

    //创建软键盘，软键盘可能为多个窗口服务，所以父对象是活动屏幕
    lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
    //默认隐藏
    lv_obj_add_flag(kb,LV_OBJ_FLAG_HIDDEN);

    //当聚焦某个文本输入框时，显示软键盘，并且与之关联
    //增加文本输入框的事件回调函数
    lv_obj_add_event_cb(use_ta,textarea_event_cb,LV_EVENT_ALL,(void*)kb);
    lv_obj_add_event_cb(pass_ta,textarea_event_cb,LV_EVENT_ALL,(void*)kb);

    //创建登录按钮，以登录窗口为父对象
    lv_obj_t * but = lv_button_create(win);
    //设置大小和位置
    lv_obj_set_size(but,120,65);
    lv_obj_set_pos(but,330,330);
    //初始化按钮样式表
    init_button_style();
    //对于按钮而言，需要创建一个标签作为子对象，用来显示文本
    lv_obj_t * lab = lv_label_create(but);
    lv_label_set_text(lab,"login");

    lv_obj_add_style(but,&button_style,LV_STATE_DEFAULT);

    lv_obj_add_event_cb(but,button_click_event_cb,LV_EVENT_CLICKED,(void*)win);


}



